//防抖函数高阶用法
export function antiShake(func, timeout = 2000, immediately) {
  let timeId = null
  return function (...args) {
    clearTimeout(timeId)
    if (immediately) {
      let firstRun = !timeId
      timeId = setTimeout(() => {
        timeId = null
      }, timeout);
      if (firstRun) {
        func.apply(this, args)
      }
    }else{
      timeId = setTimeout(() => {
        func.apply(this, args)
      }, timeout);
    }
  }
}